package com.xxx.modules.sys.service.impl;

import com.xxx.modules.sys.dao.SysUserAttentionMapper;
import com.xxx.modules.sys.domain.SysUserAttentionDomain;
import com.xxx.modules.sys.service.SysUserAttentionService;
import com.xxx.modules.sys.service.UserAttentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by ChenXuefei on 2017/10/17.
 */
@Service("userAttentionService")
public class UserAttentionServiceImpl implements UserAttentionService {

    @Autowired
    private SysUserAttentionService sysUserAttentionService;

    @Override
    public void addUserAttention(String attentionId, String isAttentionedId) {
        SysUserAttentionDomain sysUserAttentionDomain = new SysUserAttentionDomain();
        sysUserAttentionDomain.setAttentionId(Long.valueOf(attentionId));
        sysUserAttentionDomain.setIsAttentionId(Long.valueOf(isAttentionedId));
        //0 关注  1 取消关注
        sysUserAttentionDomain.setState(0);
        sysUserAttentionDomain.setCreateTime(new Date());
        sysUserAttentionDomain.setUpdateTime(sysUserAttentionDomain.getCreateTime());
        sysUserAttentionService.add(sysUserAttentionDomain);
    }

    @Override
    public void updateUserAttentionState(String attentionId, String isAttentionedId) {
        SysUserAttentionDomain sysUserAttentionDomain = new SysUserAttentionDomain();
        sysUserAttentionDomain.setAttentionId(Long.valueOf(attentionId));
        sysUserAttentionDomain.setIsAttentionId(Long.valueOf(isAttentionedId));
        List<SysUserAttentionDomain> sysUserAttentionDomains = sysUserAttentionService.queryByList(sysUserAttentionDomain);

        SysUserAttentionDomain userAttentionDomain = sysUserAttentionDomains.get(0);
        //0 关注  1 取消关注
        userAttentionDomain.setState(1);
        userAttentionDomain.setUpdateTime(new Date());

        sysUserAttentionService.updateBySelective(userAttentionDomain);
    }
}
